package com.novoda.runbuddy.view;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.novoda.runbuddy.activity.stopwatch.StopwatchTools;
import com.novoda.runbuddy.controller.IDayController;
import com.novoda.runbuddy.model.Jog;
import com.novoda.runbuddy.model.ListOfJogs;

public class JogListAdapter extends BaseAdapter {

	private ListOfJogs		jogEntries;
	private final Activity	activity;
	private IDayController	dayOfJogDetailsController;

	public JogListAdapter(Activity activity, ListOfJogs jogEntries, IDayController dayOfJogDetailsController) {
		this.activity = activity;
		this.jogEntries = jogEntries;
		this.dayOfJogDetailsController = dayOfJogDetailsController;
	}

	public int getCount() {
		return this.jogEntries.size();
	}

	public Jog getItem(int position) {
		return this.jogEntries.get(position);
	}

	public long getItemId(int position) {
		return this.jogEntries.get(position)._id;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		TextView miles;
		TextView jogname;
		TextView timerun;

		miles = new TextView(activity);
		miles.setText("00");

		jogname = new TextView(activity);
		jogname.setText(jogEntries.get(position).name);

		timerun = new TextView(activity);
		timerun.setText(StopwatchTools.getFormattedDiff(jogEntries.get(position).getStartTime(), jogEntries.get(position)
				.getStopTime()));

		JogEntryView todayView = new JogEntryView(activity, miles, jogname, timerun, jogEntries.get(position).startTime,
				dayOfJogDetailsController);
		return todayView;
	}

}
